package com.sghd.fight.module.game.service.skill.effect;

import com.sghd.fight.module.game.config.SkillConfig;
import com.sghd.fight.module.game.core.model.Unit;
import com.sghd.fight.module.game.service.room.IRoom;
import com.sghd.fight.module.game.service.skill.Context;
import com.sghd.pojo.fight.game.SkillReport;
import com.sghd.pojo.fight.game.TargetReport;
import com.sghd.pojo.fight.game.UnitValue;
import com.sghd.pojo.fight.game.ValueItem;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author frank
 * @date 2018-11-21 14:45
 * @desc 寒冰剑
 **/
@Component
public class IceEffect implements Effect {
    Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void execute(Context context, IRoom room, Unit owner, Unit target, Map<String, Object> ctx, SkillReport skillReport, TargetReport targetReport, SkillConfig config) {
        int level = owner.getSkillLevel(config.getId());//玩家技能等级
        //不同等级对应的攻击力
        Map<String, Object> skillCtx = MapUtils.getMap(ctx, String.valueOf(level));
        //寒冰剑基础攻击力
        int attack = MapUtils.getIntValue(skillCtx, Effect.ATTACK);
        //计算公式
        int val = (int) (attack * getBet(owner, target));
        val = fixHp(owner, target, val, room, config);
        context.addValue(target, UnitValue.HP, -val);
        targetReport.addValue(ValueItem.valueOf(UnitValue.HP, -val));
    }

    @Override
    public EffectType getType() {
        return EffectType.SK_ICE;
    }
}
